import prisma from "@/app/utils/prismadb";
import serverAuth from "@/app/utils/serverAuth";
import { NextResponse } from "next/server";

export const GET = async ()=>{
    try {
         await serverAuth();
         const movieCount = await prisma.movie.count();
         const randomIndex = Math.floor(Math.random() * movieCount);
         const randomMovie = await prisma.movie.findMany({take:1,skip:randomIndex})
        // console.log("currentUser",currentUser)
        return  NextResponse.json({ data: randomMovie[0] }, { status: 200 })
    } catch (error) {
        console.log('current',error)
        return NextResponse.json({ message:"Internal server error" }, { status: 400 })
    }

}





